package com.glela.order.service;

import java.util.List;
import java.util.Map;
import org.springframework.http.ResponseEntity;
import com.glela.api.model.AlipayAppKeyInfo;
import com.glela.api.model.PayAppKeyInfo;
import com.glela.common.exception.PlatformException;
import com.glela.goods.model.vo.InventoryVo;
import com.glela.order.model.AfterSales;
import com.glela.order.model.Commision;
import com.glela.order.model.ExpressCompany;
import com.glela.order.model.OrderInfo;
import com.glela.order.model.OrderObject;
import com.glela.order.model.OrderPay;
import com.glela.order.model.OrderSettlement;
import com.glela.order.model.OrderSettlementCommision;
import com.glela.order.model.PayTypeConfig;
import com.glela.order.model.request.RequestGetOrderObject;
import com.glela.order.model.request.RequestOrderDetail;
import com.glela.order.model.response.OrderInfoVo;
import com.glela.order.model.response.RespAddOrderInfo;
import com.glela.order.model.response.ResponseGetOrderObject;
import com.glela.order.model.response.ResponseOrderNum;
import com.glela.order.model.response.ResponseShopOrderNum;
import com.glela.order.vo.OrderSettlementVo;
import com.glela.platform.model.BaseRestrictions;
import com.glela.platform.model.CUserPointTransaction;
import com.glela.platform.model.User;
import com.glela.platform.model.UserJournal;
import com.glela.platform.model.UserPointJournal;
import com.glela.platform.model.request.ReqHeaderVo;
import com.glela.platform.model.request.RequestPageBaseModel;
import com.glela.platform.model.response.ResponseResultModel;
import com.glela.platform.model.response.ResponseUser;

/**
 * @author liujie
 * @2016年10月25日
 */
public interface OrderService {

	public ResponseGetOrderObject getOrderObject(RequestGetOrderObject requestGetOrderObject) throws PlatformException;

	/**
	 * <dl>
	 * <dt>获取去结算订单信息</dt>
	 * </dl>
	 * @param requestGetOrderObject
	 * @return ResponseResultModel<?>
	 * @author zls
	 * @date 2017年7月20日 下午6:22:07
	 */
	ResponseResultModel<?> getToOrderInfo(RequestGetOrderObject requestGetOrderObject);

	/** 可用优惠券 */
	ResponseResultModel<?> getAvlRedPacketList(RequestGetOrderObject requestGetOrderObject);

	public String addOrderObject(RequestOrderDetail requestOrderDetail) throws PlatformException;
	/**
	 * <dl>
	 * <dt>生成订单</dt>
	 * </dl>
	 * @param requestOrderDetail
	 * @return ResponseResultModel<?>
	 * @author zls
	 * @date 2017年7月20日 下午8:30:04
	 */
	public ResponseResultModel<RespAddOrderInfo> addOrderInfo(RequestOrderDetail requestOrderDetail) throws PlatformException;
	public boolean addCommision(ResponseUser user, OrderObject orderObject, Map<Long, InventoryVo> inventoryMap, Map<Long, OrderInfo> orderInfoIdMap,Map<String,BaseRestrictions> baseRestrictionsMap) throws PlatformException;

	boolean addCommision(ResponseUser user, OrderObject orderObject, Map<Long, InventoryVo> inventoryMap, Map<Long, OrderInfo> orderInfoIdMap) throws PlatformException;
	
	/**
	 * <dl>
	 * <dt>获取可分佣交易单</dt>
	 * </dl>
	 * @return List<OrderObject>
	 * @author zls
	 */
	public List<OrderObject> selectOrderObjectForCommision();

	public List<Commision> selectByOrderObjectIdForCommision(long orderDetailId);
	
	public List<Map<String, Object>> selectOrderObjectCommision(String  OrderDetailIds);

	/**
	 * <dl>
	 * <dt>查询未处理分佣信息(仅查找账务类型是 1 2 3 17{开店 直接 间接分佣 角色级别分佣})</dt>
	 * </dl>
	 * @param orderObjectList
	 * @return List<Commision>
	 * @author gaoweiqi
	 */
	public List<Commision> selectInOrderObjectIdForCommision(List<OrderObject> orderObjectList);
	/**
	 * <dl>
	 * <dt>查询未处理妆币信息(仅查找账务类型是 12 {消费送妆币})</dt>
	 * </dl>
	 * @param orderObjectList
	 * @return List<Commision>
	 * @author gaoweiqi
	 */
	public List<CUserPointTransaction> selectInOrderObjectIdForPoint(List<OrderObject> orderObjectList);

	/**
	 * <dl>
	 * <dt>获取可分佣订单信息</dt>
	 * </dl>
	 * @param orderObjectList itme.id 交易单id
	 * @return List<OrderInfo>
	 * @author zls
	 */
	public List<OrderInfo> selectOrderInfoInOOIdForCommision(List<OrderObject> orderObjectList);
	
	
	public OrderObject selectOrderObjectByOrderSn(String orderSn);
	
	/**
	 * <dl>
	 * <dt>添加结算单的消息队列</dt>
	 * </dl>
	 * @param orderSn 交易单号
	 * @author gwq
	 */
	public void addMQPayCallBack(String orderSn);
	 
	/**
	 * <dl>
	 * <dt>更新支付信息</dt>
	 * </dl>
	 * @param orderSn 交易单号
	 * @param payType 支付类型
	 * @param paymentFee 实际支付金额
	 * @param payId 第三方支付流水号
	 * @throws PlatformException 业务异常
	 * @author zls
	 */
	public void updatePayOrderInfo(String orderSn, int payType, int paymentFee, String payId) throws PlatformException;

	/**
	 * <dl>
	 * <dt>支付成功，支付订单相关信息</dt>
	 * </dl>
	 * @param orderSn 结算单号
	 * @param orderPay 支付信息
	 * @param paymentFee 支付金额（分）
	 * @param payId 第三方流水号
	 * @throws PlatformException
	 * @author zls
	 * @date 2017年12月6日 下午1:29:11
	 */
	void updatePayOrderInfo(String orderSn, OrderPay orderPay, long paymentFee, String payId) throws PlatformException;

	public AlipayAppKeyInfo getAlipayAppKeyInfo();
	
	public PayAppKeyInfo getPayAppKeyInfo(int payType);
	
	/**
	 * <dl>
	 * <dt>推送订单到oms</dt>
	 * </dl>
	 * @param orderSn 交易单号
	 * @param payId 第三方支付流水号
	 * @param payType 支付类型
	 * @throws PlatformException 业务异常
	 * @author zls
	 * @param t_id 
	 */
	public void updateOrderForXZOMS(String orderSn,String payId,Integer payType, String t_id) throws PlatformException;
	
	/**
	 * 获取支付类型配置
	 * @param status 状态：0禁用；1启用
	 * @return List<PayTypeConfig>
	 */
	public List<PayTypeConfig> selectPayTypeConfigByStatus(Integer status);
	
	public int updateSettlementStatusByID(Long ID, int status,String settlementNo,String companyAccount,String managerAccount,int selfSupport);
	
	public int updateSettlementStatusByOrderSn(String orderSn, int status,String settlementNo);
	
	public List<OrderSettlementVo> selectByOrderSnForSettlement(String orderSn);
	
	public List<OrderSettlementVo> selectByOrderSnForFreightSettlement(String orderSn);
	
	public void divide(String orderSn) throws Exception;
	
	public int updateOrderObjectPayUrlById(long id, String payUrl);
	
	public List<OrderSettlementVo> selectByOrderSnForSettlementDetail(
			String orderSn);
	
	public List<OrderObject> selectDiTemp();
	
	/**
	 * 获取各种类型的订单数量
	 * 
	 * @author 卫耀华
	 * @param userId
	 * @return
	 */
	public ResponseOrderNum getOrderNum(Long userId);

	/**
	 * 查询订单状态
	 * 
	 * @author houmf
	 * @param orderObjectVo
	 * @return
	 */
	public List<OrderInfoVo> selectOrderInfoByStatusAndUserId(long userId, int status, int page, int pageSize);

	/**
	 * 查询达人订单
	 * 
	 * @author houmf
	 * @param orderObjectVo
	 * @return
	 */
	public List<OrderInfoVo> listTalentOrderInfo(long userId, int status, int page, int pageSize);

	/**
	 * 根据订单号查询订单详情
	 * 
	 * @author houmf
	 * @param orderObjectVo
	 * @return
	 */
	public OrderInfoVo getOrderInfoEntityByOrderSn(String orderSn,long userId);

	/**
	 * 根据父订单ID撤销当前订单
	 * 
	 * @param orderObjectId
	 * @return
	 */
	public ResponseEntity<?> editCancelOrderByOrderId(Long orderObjectId, long userId) throws Exception;
	/**
	 * 查询所有快递公司
	 * 
	 * @param orderObjectId
	 * @return
	 */
	public List<ExpressCompany> listExpreseCompany();
	
	/**
	 * 嗨购调取发货接口
	 * 
	 * @param orderObjectId
	 * @return
	 */
	public ResponseEntity<?> thirdpartyConsignment(String appKey,String data,String sign) throws Exception;

	/**
	 * 查询子订单根据子订单单号
	 * @param orderSn
	 * @return
	 */
	public OrderInfo selectOrderInfoByOrderInfoSn(String orderSn);

	/**
	 * 售后信息查询
	 * @param customerServiceNumber
	 * @return
	 */
	public AfterSales selectAfterSalesByCustomerServiceNumber(String customerServiceNumber);

	public ResponseEntity<?> confirmOrder(long orderInfoId) throws Exception;
	
	/**
	 * <dl>
	 * <dt>记录购买会员订单支付信息，并激活会员</dt>
	 * </dl>
	 * @param orderSn 交易单号
	 * @param payType 支付类型
	 * @param paymentFee 支付回调金额
	 * @param payId 第三方支付流水号
	 * @author zls
	 */
	public void confirmOrderVip(String orderSn, int payType, int paymentFee, String payId) throws Exception;

	public OrderObject selectOrderObjectByOrderObjectId(Long orderObjectId);

	/**
	 * 获取退款的分账信息
	 * @param orderDetailId
	 * @return
	 */
	public String selectDivideString(Long orderDetailId);

	/**
	 * 记录邮费退款情况
	 */
	public void updateOrderObjectFreightNo(Long orderObjectId, String refundFeeNo);

	/**
	 * 查询商品的类型
	 * @param id
	 * @return
	 */
	public int selectDetailGoodsType(Long id);

	/**
	 * 查询邮费结算账号
	 * @param orderObjectId
	 * @return
	 */
	public String selectSettlementAccount(Long orderObjectId);

	
	public List<String> selectOrderClearing();
	
	public void disposeOrderSettlement();
	
	public void OrderSettlement();
	
	public void OrderSettlementartificialEliminate(List<String> orderObjectSn);

	/**
	 * <dl>
	 * <dt>查询订单所有推荐人信息</dt>
	 * </dl>
	 * @param id 交易单id
	 * @return List<User>
	 * @author zls
	 * @date 2017年6月23日 下午5:26:48
	 */
	public List<User> selectOrderRecommendFromUser(Long id);

	/**
	 * <dl>
	 * <dt>处理余额事务和妆币事务</dt>
	 * </dl>
	 * @author gwq
	 * @param commisionList 余额事务信息
	 * @param userJournalList 余额事务流水
	 * @param pointTransactionList 积分事务信息
	 * @param userPointJournalList 积分事务流水
	 * @param orderObjectList 可处理的订单集合
	 * @throws PlatformException 业务异常
	 */
	public void autoCommision(List<Commision> commisionList,
			List<UserJournal> userJournalList,
			List<CUserPointTransaction> pointTransactionList,
			List<UserPointJournal> userPointJournalList,
			List<OrderObject> orderObjectList) throws PlatformException ;

	String selectFreightDivideString(OrderSettlement settlement);
	
	/***
	 * 按行更新结算表中的状态相关信息
	 * @param orderSn
	 * @param status
	 * @param settlementNo
	 * @param companyAccount
	 * @param managerAccount
	 * @param selfSupport
	 * @return
	 */
	public int updateStatusBySettlementId(Long settlementId, int status,String settlementNo,String companyAccount,String managerAccount);

	/**
	 * <dl>
	 * <dt>比较分账信息</dt>
	 * </dl>
	 * @author gwq
	 * @param listSettle 系统记录的订单分账信息
	 * @param divide 易宝记录的分账信息
	 * @return "1"：比对成功 "2"：比对失败 
	 */
	public String compareDivide(List<OrderSettlementVo> listSettle,
			Map<String, Double> YeePayDivide);

	/**
	 * <dl>
	 * <dt>验证订单</dt>
	 * </dl>
	 * @author gwq
	 * @param orderObj 即将验证的父订单
	 * @return Map<String, Object>  "key"：父订单号 "value":异常信息
	 */
	public Map<String, Object> validationOrderObj(OrderObject orderObj) throws Exception;

	/**
	 * <dl>
	 * <dt>生成结算单返利单</dt>
	 * </dl>
	 * @author gwq
	 * @param orderSn 父订单号
	 * @return boolean 
	 */
	public boolean addOrder_settlement_commision(String orderSn)throws Exception;
	/**
	 * <dl>
	 * <dt>生成结算单返利单</dt>
	 * </dl>
	 * @author gwq
	 * @param orderSettlementCommision 订单信息
	 * @return boolean 
	 */
	public boolean addOrder_settlement_commision(OrderSettlementCommision orderSettlementCommision) throws Exception;
	
	
	public Map<String,Object> canOrder(RequestOrderDetail reqOrderDetail);


    public OrderInfoVo getOrderInfoEntityByOrderSnNew(RequestPageBaseModel requestPageBaseModel);

    public ResponseShopOrderNum getShopOrderNum(Long userId);

    public ResponseShopOrderNum getShopOrderNumNew(Long userId);

	/** 是否是首单用户 */
	public boolean isFirstOrder(Long userId);

	public ResponseResultModel<RespAddOrderInfo> overseaGoodsInfo(ResponseResultModel<RespAddOrderInfo> addOrderInfo, RequestOrderDetail reqOrderDetail);
}
